#!/usr/bin/python

import math


s = 0
for x in [1, 2, 3, 4]:
    s += x
print (x, s)



# Seek prime numbers between 50 - 100
for i in range (50, 100+1):
    for j in range (2, int (math.sqrt(i)) + 1):
        if i % j == 0:
            break;
    else:
        print i


print '-----------------------------'

# Place the else in the same indentation as the if
for i in range(50, 100+1):
    for j in range(2, int(math.sqrt(i)) + 1):
        if i % j == 0:
            break;
        else:
            print i


print '-----------------------------'

# Add a break statement after else
for i in range(50, 100+1):
    for j in range(2, int(math.sqrt(i))+1):
        if i % j == 0:
            break;
        else:
            print i
            break

# for loop
for letter in 'Python':
    print 'current letter:', letter

for letter in 'Python':
    print 'current letter:', letter


# Once upon a time
fruits = ['banana', 'apple', 'mango']
for fruit in fruits:
    print "current fruit:", fruit

# From behind
fruitss = {'banana', 'apple', 'mango'}
for i in fruitss:
    print "current fruit:", i


# enumerate
sequence = [12, 34, 34, 23, 45, 76, 89]
for i, j in enumerate(sequence):
    print i, j


sequence = [12, 34, 34, 23, 45, 76, 89]
for i  in sequence:
    print i

sequence = [12, 34, 34, 23, 45, 76, 89]
for i in enumerate(sequence):
    print i


test_list = [2, "Jone", 3, 6, 7, 'hongten', 'hanyuan', 'good', "Tom"]
print test_list
print (len(test_list))

# Traversal list
for i in test_list:
    print (i)

test_list = [2, "Jone", 3, 6, 7, 'hongten', 'hanyuan', 'good', "Tom"]
print test_list
print (len(test_list))

# Traversal list
for i in test_list:
    print (i)


test_tuple = [("a", 1), ("b", 2), ("c", 3), ("d", 4)]
print test_tuple

for i in test_tuple:
    print i

# Traversing a tuple
for (i, j) in test_tuple:
    print (i, j)


# Dictionary iterator
test_dict = {'name':'hongten', 'age':'20', 'gender':'M', 'sports':'football,table tennis, swimming'}
for key in test_dict:
    print (key + ':' + test_dict[key])


# Merge two lists using zip

L1 = [1,3,5,7]
L2 = [2,4,6,8]
print zip(L1, L2)

for (i, j) in zip(L1,L2):
    print (i, j)

print ('###################################')

L3 = L2[:]
L3.remove(8)
print ('L1, L3 list is:')
print L1
print L3

# it can be seen that when the length is different,
# the excess is ignored
for (i, j) in zip(L1, L3):
    print (i, j)


# Use zip to construct a dictionary
test_keys = ['name', 'age', 'gender', 'weight', 'hight']
test_values = ['Hongten', '20', 'M', '55', '170']

print ('Keys in a dictionary:')
print (test_keys)

print ('Key in the dictionary corresponds to the value:')
print (test_values)

print ('After constructing dictionary:')
test_dic = dict(zip(test_keys, test_values))

for key in test_dic:
    print (key + ':' + test_dic[key])




